<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="贾文清">
    <title></title>
    <style>
        main {
            width: 200px;
            margin: 0 auto;
            display: flex;
        }

        main div {
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
        }

        .first {
            background-color: lightgreen;
        }

        .second {
            background-color: lightgray;
            cursor: pointer;
        }

        section {
            border: 1px solid lightgray;
            display: none;
        }

        section p {
            margin: 0;
            border-bottom: 1px dashed lightgray;
        }
        a{
            text-decoration: none;
            color: black;
        }
    </style>
</head>

<body>
    <main>
        <div class="first">选择项目:</div>
        <div class="second">
            <a href="javascript:;">未选择</a>
            <section>
                <p>html5</p>
                <p>css3</p>
                <p>JavaScript</p>
                <p>jquery</p>
            </section>

        </div>
    </main>
    <script src="./jquery.js"></script>
</body>

</html>
<script>
    // var a = $('a');
    $('.second').click(function () {
        $('section').show();
        $('p').hover(function () {
            $(this).css('background-color', 'lightgray').siblings().css('background-color', 'white');
            // 点击p标签section消失
             $('section>p').click(function (ev) {
                  //  阻止触发的目标元素继续冒泡
                  ev.stopPropagation();
             var p =$(this).text();
             $('a').text(p);
             $('section').hide();
        });
        }, function () {
            $(this).css('background-color', 'white')
        })
    });

</script>